package io.xiyou.user.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.xiyou.user.api.IUserService;
import io.xiyou.user.api.bo.UpdateUserBO;
import io.xiyou.user.api.dto.UserDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户接口
 *
 * @author 西柚
 * @date 2021-10-21 15:00:27
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/user")
@Api(value = "/user", tags = "用户接口")
public class UserController {

    @Autowired
    private IUserService userService;

    @ApiOperation("根据用户ID查询用户信息")
    @GetMapping("/getByUserId")
    @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "Long", paramType = "query")
    public UserDTO getByUserId(@RequestParam("userId") Long userId) {
        return userService.getByUserId(userId);
    }

    @ApiOperation("修改用户信息")
    @PostMapping("/update")
    public UserDTO update(@RequestBody UpdateUserBO updateUserBO) {
        return userService.update(updateUserBO);
    }

    @ApiOperation("删除用户")
    @GetMapping("/delete")
    @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "Long", paramType = "query")
    public Integer delete(@RequestParam("userId") Long userId) {
        return userService.delete(userId);
    }

    @ApiOperation("计数器")
    @GetMapping("/counter")
    @ApiImplicitParam(name = "key", value = "key", required = true, dataType = "String", paramType = "query")
    public Long delete(@RequestParam("key") String key) {
        return userService.counter(key);
    }

}
